<?php

/**
 * @file
 * Creates the administration tab and interface which allows
 * the developer to easily recreate and populate the database.
 * @version 8/9/11
 * @author Matt Vartanian
 */
include_once ("..\db-control\dbInstall.php");
include_once("header.php");
administration( );

/**
 * @function administration
 * Calls administrationHeader from header.php and calls viewAdministrationForm
 * function with sql login information.
 */
function administration()
{
	administrationHeader();
	$host = "";
	$database = "";
	$username = "";
	$password = "";

	viewAdministrationForm($host, $database, $username, $password);
	if(isset($_POST['createDatabaseAndTables'])){
		getPostVars($host, $database, $username, $password);
		createDatabaseAndTables($host, $database, $username, $password);
	}

	if(isset($_POST['populateDatabase'])){
		populateDatabase();
	}
}

/**
 * @function viewAdministrationForm
 * Creates login form for database.
 * @param string $host is the host name of the server
 * @param string $database is the name of the database on the server
 * @param string $username is the name of the user on the server
 * @param string $password is the user's password on the server
 */
function viewAdministrationForm($host, $database, $username, $password)
{
	echo <<<_END
	<div id="rightcolumn">

  	  <form method="post" action="administration.php">
  	    <pre>
      Server Name or IP         <input type="text" name="host" /> 
      MySQL Login Name          <input type="text" name="username" /> 
      MySQL Login Password      <input type="password" name="password" />
      Name of Database          <input type="text" name="database" />
      <input type="submit" value="Create Database and Tables" name="createDatabaseAndTables" /><input type="submit" value="Populate Database" name="populateDatabase" />
        </pre>
      </form>
    </div>
    </div>
_END;
}

/**
 * @function getPostVars
 * Collects database login information from the form
 * @param string $host is the host name of the server
 * @param string $database is the name of the database on the server
 * @param string $username is the name of the user on the server
 * @param string $password is the user's password on the server
 */
function getPostVars(&$host, &$database, &$username, &$password)
{
	$host = $_POST['host'];
	$username = $_POST['username'];
	$password = $_POST['password'];
	$database = $_POST['database'];
}

?>